<?php 
include './c/config.php';



$dbhost='121.41.203.38'; //web1
$mysqliSet = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqliSet->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
$query=$mysqliSet->query("SELECT id FROM `uinfo` WHERE `f1` IS NULL ORDER BY `id` desc LIMIT 0,1");
if($query->num_rows>0){
    
}else{
    exit;
}

$getD=$query->fetch_assoc();
$id=$getD['id'];
$UserFen=0;



//填空
$tkong=json_decode(file_get_contents('./template/mi/tkong.txt'), true);

$tiData=array();
foreach ($tkong as $k=>$v){
    $tiData[($k+1)]=$v['a'];
}

$dbhost = '121.41.197.22';
echo $dbhost;
echo "<br />";
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}

$query=$mysqli->query("SELECT * from `tiankong` where uid='".$id."' order by id desc  limit 0,1 ");
if($query->num_rows>0){
    $getUTk=$query->fetch_assoc();
    $yhtj=json_decode($getUTk['yhtj'], true);
    $fen=0;
    foreach ($yhtj as $key => $value){
        foreach ($value as $k => $v ){
           // echo $k, '.....', $v, '.....'; //$tiData[$k]
            if(trim($v) == trim($tiData[$k])){
                $fen++;
                echo '.....对了';
            }
           // echo "<br />";
        }
    }
    echo "<br />";
    echo $fen,'分';
}
if ($fen > 0){
    $UserFen=$fen;
}
$mysqli->close();

$dbhost='121.41.203.38'; //web1
echo $dbhost;
echo "<br />";
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
$query=$mysqli->query("SELECT * from `tiankong` where uid='".$id."' order by id desc  limit 0,1 ");
if($query->num_rows>0){
    $getUTk=$query->fetch_assoc();
    $yhtj=json_decode($getUTk['yhtj'], true);
    $fen=0;
    foreach ($yhtj as $key => $value){
        foreach ($value as $k => $v ){
            // echo $k, '.....', $v, '.....'; //$tiData[$k]
            if(trim($v) == trim($tiData[$k])){
                $fen++;
                //echo '.....对了';
            }
            // echo "<br />";
        }
    }
    echo "<br />";
    echo $fen,'分';
}

if ($fen > $UserFen){
    $UserFen=$fen;
}

$mysqli->close();

echo "<br />";
echo ".......<br />";
$dbhost='47.118.85.222'; //web2
echo $dbhost;
echo "<br />";

$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
$query=$mysqli->query("SELECT * from `tiankong` where uid='".$id."' order by id desc  limit 0,1 ");
if($query->num_rows>0){
    $getUTk=$query->fetch_assoc();
    $yhtj=json_decode($getUTk['yhtj'], true);
    $fen=0;
    foreach ($yhtj as $key => $value){
        foreach ($value as $k => $v ){
            // echo $k, '.....', $v, '.....'; //$tiData[$k]
            if(trim($v) == trim($tiData[$k])){
                $fen++;
               // echo '.....对了';
            }
            // echo "<br />";
        }
    }
    echo "<br />";
    echo $fen,'分';
}
$mysqli->close();
if ($fen > $UserFen){
    $UserFen=$fen;
}

echo "<br /><br />";
echo $id,' :填空题分:';
echo $UserFen;
$mysqliSet->query(" update  `uinfo` set f1='".$UserFen."'  WHERE id='".$id."' ");

$mysqliSet->close();




echo '
<script>
window.setTimeout(function(){
window.location.reload();
}, 10);
</script>
    
';

exit;
exit;







//计算分
// http://121.41.203.38/gai.php
if (isset($_GET['key']) && 'tt' == $_GET['key']){
    exit;
}else{exit;}
include './c/config.php';
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}

//判断-----
$id=14012;

$panduan=json_decode(file_get_contents('./template/mi/pand.txt'), true);
$tiData=array();
foreach ($panduan as $k=>$v){
    $tiData[($k+1)]=$v['a'];
}
$query=$mysqli->query("SELECT * from `panduan` where uid='".$id."'  limit 0,1 ");
if($query->num_rows>0){
    $getUTk=$query->fetch_assoc();
    $yhtj=json_decode($getUTk['yhtj'], true);
    //var_dump($yhtj);
    echo "<br><br>";
    $fen=0;
    foreach ($yhtj as $key => $value){
        foreach ($value as $k => $v ){
            echo $k, '.....', $v, '.....';//$tiData[$k];
            $getUserVal='';
            if('n' == trim($v)){
                $getUserVal='错误';
            }
            if('y' == trim($v)){
                $getUserVal='正确';
            }
            if($getUserVal == trim($tiData[$k])){
                $fen++;
                echo '.....对了';
            }
            echo "<br />";
        }
    }
    echo "<br />";
    echo $fen,'分';
}


//判断----- end

exit;

//多选------
$id=14012;
$duoxuan=json_decode(file_get_contents('./template/mi/duo.txt'), true);
$tiData=array();
foreach ($duoxuan as $k=>$v){
    $tiData[($k+1)]=$v['a'];
}
$query=$mysqli->query("SELECT * from `duoxuan` where uid='".$id."'  limit 0,1 ");
if($query->num_rows>0){
    $getUTk=$query->fetch_assoc();
    $yhtj=json_decode($getUTk['yhtj'], true);
    //var_dump($yhtj);
    echo "<br><br>";
    $fen=0;
    foreach ($yhtj as $key => $value){
        foreach ($value as $k => $v ){
            echo $k, '.....', $v, '.....';//$tiData[$k];
            $tmpTiVal=str_replace(',', '', strtolower(trim($tiData[$k])));
            if(trim($v) == $tmpTiVal){
                $fen++;
                echo '.....对了';
            }
            echo "<br />";
        }
    }
    echo "<br />";
    echo $fen,'分';
}


//多选------end
exit;

//单选------
$id=12717;
$danxuan=json_decode(file_get_contents('./template/mi/dx.txt'), true);
$tiData=array();
foreach ($danxuan as $k=>$v){
    $tiData[($k+1)]=$v['a'];
}
//var_dump($tiData);

$query=$mysqli->query("SELECT * from `danxuan` where uid='".$id."'  limit 0,1 ");
if($query->num_rows>0){
    $getUTk=$query->fetch_assoc();
    $yhtj=json_decode($getUTk['yhtj'], true);
    //var_dump($yhtj);
    echo "<br><br>";
    $fen=0;
    foreach ($yhtj as $key => $value){
        foreach ($value as $k => $v ){
            echo $k, '.....', $v, '.....';//$tiData[$k];
            $tmpTiVal=strtolower(trim($tiData[$k]));
            if(trim($v) == $tmpTiVal){
                $fen++;
                echo '.....对了';
            }
            echo "<br />";
        }
    }
    echo "<br />";
    echo $fen,'分';
}


//单选------ end

exit;
//填空
$id=9723;
$tkong=json_decode(file_get_contents('./template/mi/tkong.txt'), true);
$tiData=array();
foreach ($tkong as $k=>$v){
    $tiData[($k+1)]=$v['a'];
}

$query=$mysqli->query("SELECT * from `tiankong` where uid='".$id."'  limit 0,1 ");
if($query->num_rows>0){
    $getUTk=$query->fetch_assoc();
    $yhtj=json_decode($getUTk['yhtj'], true);
    
    echo "<br><br>";
    $fen=0;
    foreach ($yhtj as $key => $value){
        foreach ($value as $k => $v ){
            echo $k, '.....', $v, '.....'; //$tiData[$k]
            if(trim($v) == trim($tiData[$k])){
                $fen++;
                echo '.....对了';
            }
            echo "<br />";
        }
    }
    
    echo "<br />";
    echo $fen,'分';

}

$mysqli->close();